
import React from 'react';

import styles from './User.css';

import UserNav from "../../components/user/UserNav";
import UserBody from "../../components/user/UserBody";
import UserModelPros from "../../components/pros/UserModelPros";
import UserPoint from "../../components/user/UserPoint";
import UserGift from "../../components/user/UserGift";
import UserMessage from "../../components/user/UserMessage";
import UserLoophole from "../../components/user/UserLoophole";



class User extends React.Component<UserModelPros,any>{

  constructor(props) {
    super(props);
  }

  showBody(){
    const {state} = this.props.location;
    if(state== undefined) {
      return (<UserBody/>);
    } else if(state.bodyName =='point'){
      return (<UserPoint/>);
    } else if(state.bodyName =='gift'){
      return (<UserGift />);
    } else if(state.bodyName =='message'){
      return (<UserMessage />);
    } else if(state.bodyName =='userLoophole'){
      return (<UserLoophole />);
    }else{
      return (<UserBody/>);
    }
  }

  componentWillMount(){
    let username = sessionStorage.getItem('username');
    if(username ==undefined ||username ==''){
      window.document.location.href='/point-shopping';
    }
  }

  render() {
    const {state} = this.props.location;
    return (
      <div className={[styles.container,styles["container-user"]].join(' ')}>
        <div>
          <div className={[styles.section,styles["section-subnav"]].join(' ')}>
            <div className={styles.section_subnav}>
              <p className={styles.subnav_title}>个人中心</p>
            </div>
          </div>

          <div className={styles.section}>
            <div className="section_user">
              <UserNav bodyName={state==undefined?"index":state.bodyName}/>
              {this.showBody()}
            </div>
          </div>

        </div>
      </div>
    );
  }
}

export default User;
